﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MVCGenerator
{
    public class EditCSHtml
    {
        SpaceStackStringBuilder sb = new SpaceStackStringBuilder();

        public EditCSHtml(String NamespaceName, String PropertyClassName, String PropertyClassPrimaryKeyName, bool UsingDropDownLists)
        {
            if (UsingDropDownLists)
            {
                sb.AppendLine("@model " + NamespaceName + ".Models." + PropertyClassName + "CreateOrEdit");
            }
            else
            {
                sb.AppendLine("@model " + NamespaceName + "." + PropertyClassName + "");
            }

            sb.AppendLine();
            sb.AppendLine("@{");
            if (true)
            {
                sb.AddSpace();
                sb.AppendLine(@"ViewBag.Title = ""Edit"";");
                sb.RemoveSpace();
            }
            sb.AppendLine("}");
            sb.AppendLine();
            sb.AppendLine("<h2>Edit</h2>");
            sb.AppendLine("");
            sb.AppendLine("@using (Html.BeginForm()) {");
            if (true)
            {
                sb.AddSpace();
                sb.AppendLine("@Html.ValidationSummary(true)");
                sb.AppendLine("<fieldset>");
                if (true)
                {
                    sb.AddSpace();
                    sb.AppendLine("<legend>" + PropertyClassName + "</legend>");
                    sb.AppendLine();
                    sb.AppendLine("@Html.HiddenFor(model => model." + PropertyClassPrimaryKeyName + ")");
                    sb.AppendLine(@"@Html.Partial(""_CreateOrEdit"", Model)");
                    sb.AppendLine();
                    sb.AppendLine("<p>");
                    if (true)
                    {
                        sb.AddSpace();
                        sb.AppendLine(@"<input type=""submit"" value=""Save"" />");
                        sb.RemoveSpace();
                    }
                    sb.AppendLine("</p>");
                    sb.RemoveSpace();
                }
                sb.AppendLine("</fieldset>");
                sb.RemoveSpace();
            }
            sb.AppendLine("}");
            sb.AppendLine();
            sb.AppendLine("<div>");
            if (true)
            {
                sb.AddSpace();
                sb.AppendLine(@"@Html.ActionLink(""Back to List"", ""Index"")");
                sb.RemoveSpace();
            }
            sb.AppendLine("</div>");
        }

        public override string ToString()
        {
            return sb.ToString();
        }
    }

    
}
